<?php
/**
 * Created by PhpStorm.
 * User: DreamMav
 * Date: 2019/6/5
 * Time: 23:48
 */
include "../util/DBUtil.php";
include "../util/PromptAction.php";
$db = new DBUtil();
$sql = "select * from tb_course";
$course_result = $db->query($sql);//获取所有课程

$stuId = $_POST['stuId'];
$score = array();//分数
$courseId = array();//课程id
$i = 0;
foreach ($course_result as $item) {
    $p = 'score' . $item['id'];
    $score[$i] = $_POST[$p];
    $courseId[$i] = $item['id'];
//    echo $score[$i]."\n";
    $i++;
}
$action = $_GET['action'];//判断操作类型
//修改
if ($action=="edit") {
    $sql = "update tb_score set score = ? where student_id=? and course_id=? ";
}elseif($action="add"){//添加操作
    $sql = "insert into tb_score(score,student_id,course_id) values (?,?,?)";
}
//print_r("stuId=".$stuId);
//print_r("courseTd=".$courseId);
//print_r("score=".$score);
//echo "sql = ".$sql;
for ($j = 0, $len = count($score); $j < $len; $j++) {
    $params = array($score[$j], $stuId, $courseId[$j]);
    $statue = $db->update($sql, $params);
}

showStatue($statue);
echo "<script>window.open('../view/score.php','info')</script>";

